package com.lexc.watermq.broker.config;

import com.alibaba.fastjson2.JSON;
import com.lexc.watermq.broker.cache.CommonCache;
import com.lexc.watermq.broker.model.WaterMQTopicModel;
import com.lexc.watermq.broker.utils.FileContentReaderUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * createTime：2025-08-18 15:29
 * description：broker properties loader
 */
public class TopicInfoLoader {

    public void loadProperties() {
        GlobalProperties globalProperties = CommonCache.getGlobalProperties();
        String waterMQHome = globalProperties.getWaterMQHome();
        if (StringUtils.isBlank(waterMQHome)) {
            throw new IllegalArgumentException("water mq home is null");
        }
        String waterMQTopicJson = waterMQHome + "/broker/config/watermq-topic.json";
        String fileContent = FileContentReaderUtil.readFile(waterMQTopicJson);
        List<WaterMQTopicModel> topicModelList = JSON.parseArray(fileContent, WaterMQTopicModel.class);
        CommonCache.setTopicModelList(topicModelList);
    }
}
